package com.ruoyi.system.controller;

import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import ch.qos.logback.core.joran.spi.XMLUtil;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.FxyFinancialSocialsecurity;
import com.ruoyi.system.service.IFxyFinancialSocialsecurityService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 五险一金设置表Controller
 * 
 * @author XU
 * @date 2025-02-25
 */

@RestController
@RequestMapping("/socialsecurity")
public class FxyFinancialSocialsecurityController extends BaseController {
    @Autowired
    private IFxyFinancialSocialsecurityService fxyFinancialSocialsecurityService;

    /**
     * 查询五险一金设置表列表
     */
    @RequiresPermissions("system:socialsecurity:list")
    @GetMapping("/list")
    public TableDataInfo list() {
        startPage();
        List<FxyFinancialSocialsecurity> list = fxyFinancialSocialsecurityService.selectFxyFinancialSocialsecurityList(null);
        return getDataTable(list);
    }

    /**
     * 导出五险一金设置表列表
     */
    @RequiresPermissions("system:socialsecurity:export")
    @Log(title = "五险一金设置表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FxyFinancialSocialsecurity fxyFinancialSocialsecurity) {
        List<FxyFinancialSocialsecurity> list = fxyFinancialSocialsecurityService.selectFxyFinancialSocialsecurityList(fxyFinancialSocialsecurity);
        ExcelUtil<FxyFinancialSocialsecurity> util = new ExcelUtil<FxyFinancialSocialsecurity>(FxyFinancialSocialsecurity.class);
        util.exportExcel(response, list, "五险一金设置表数据");
    }


    /**
     * 获取五险一金设置表详细信息
     */
    @RequiresPermissions("system:socialsecurity:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(fxyFinancialSocialsecurityService.selectFxyFinancialSocialsecurityById(id));
    }

    /**
     * * 新增五险一金设置表
     */
    @RequiresPermissions("system:socialsecurity:add")
    @Log(title = "五险一金设置表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody FxyFinancialSocialsecurity fxyFinancialSocialsecurity) {

        return toAjax(fxyFinancialSocialsecurityService.insertFxyFinancialSocialsecurity(fxyFinancialSocialsecurity));
    }

    /**
     * 修改五险一金设置表
     */
    @RequiresPermissions("system:socialsecurity:edit")
    @Log(title = "五险一金设置表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody FxyFinancialSocialsecurity fxyFinancialSocialsecurity) {

        return toAjax(fxyFinancialSocialsecurityService.updateFxyFinancialSocialsecurity(fxyFinancialSocialsecurity));
    }

    /**
     * 删除五险一金设置表
     */
    @RequiresPermissions("system:socialsecurity:remove")
    @Log(title = "五险一金设置表", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteByIds")
    public AjaxResult remove(@RequestBody Long[] ids) {
        return toAjax(fxyFinancialSocialsecurityService.deleteFxyFinancialSocialsecurityByIds(ids));
    }


    /**
     * 导入五险一金设置表数据
     */
    @PreAuthorize("@ss.hasPermi('system:socialsecurity:import')")
    @Log(title = "五险一金设置表", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<FxyFinancialSocialsecurity> util = new ExcelUtil<>(FxyFinancialSocialsecurity.class);
        List<FxyFinancialSocialsecurity> socialsecurityList = util.importExcel(file.getInputStream());

        String message = fxyFinancialSocialsecurityService.importSocialsecurity(socialsecurityList);
        return success(message);
    }

    /**
     * 下载导入模板
     */
    @PreAuthorize("@ss.hasPermi('system:socialsecurity:import')")
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws Exception {
        ExcelUtil<FxyFinancialSocialsecurity> util = new ExcelUtil<>(FxyFinancialSocialsecurity.class);
        util.importTemplateExcel(response, "五险一金数据");
    }

}







